package com.example.classroom.mapper;

import com.example.classroom.entity.Classroom;
import com.example.classroom.entity.UpdateClassroom;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClassroomMapper {
    @Select("SELECT * FROM ClassroomTable")
    public List<Classroom> findAll();
    @Insert("INSERT INTO ClassroomTable (building, name, capacity) VALUES (#{building}, #{name}, #{capacity})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertClassroom(Classroom classroom);
    @Delete("DELETE FROM ClassroomTable WHERE id = #{id}")
    int deleteClassroom(int id);
    @Update("UPDATE ClassroomTable SET building = #{updateClassroom.building}, name = #{updateClassroom.name}, capacity = #{updateClassroom.capacity} WHERE id = #{id}")
    int updateClassroom(int id, UpdateClassroom updateClassroom);
    @Select({
            "<script>",
            "SELECT * FROM ClassroomTable",
            "<where>",
            "<if test='name != null'>AND name = #{name}</if>",
            "<if test='building != null'>AND building = #{building}</if>",
            "<if test='capacity != null'>AND capacity = #{capacity}</if>",
            "</where>",
            "</script>"
    })
    List<Classroom> searchClassroom(String name, String building, int capacity);
}
